﻿using System;
using System.Collections.Generic;

namespace HEFramework
{
    /// <summary>
    ///
    /// 字典对象
    /// 
    /// ----------------------------------------
    /// 作者 hep
    /// 创建时间：2024-08-27 15:56:28
    /// ----------------------------------------
    /// </summary>
    public class DictionaryObject<T, A> : Dictionary<T, A>, IDisposable
    {
        private bool isDisposed;

        public DictionaryObject()
        {
        }

        /// <summary>
        /// 结合using使用来释放字典
        /// </summary>
        /// <returns></returns>
        public static DictionaryObject<T, A> Create()
        {
            var dictionary = ObjectGenerater.Instance.Fetch(typeof(DictionaryObject<T, A>)) as DictionaryObject<T, A>;
            dictionary.isDisposed = false;
            return dictionary;
        }

        public void Dispose()
        {
            if (!isDisposed)
            {
                this.Clear();
                ObjectGenerater.Instance.Recycle(this);
                isDisposed = true;
            }
        }
    }
}